package transactions.dq;

import dinamica.Db;
import dinamica.GenericTransaction;
import dinamica.Recordset;

public class DeleteSystemData extends GenericTransaction {
	public int service(Recordset inputParams) throws Throwable {
		super.service(inputParams);

		Db db = getDb();

		String table_name = inputParams.getString("table_name");
		String pk_value = inputParams.getString("pk_value");

		// 1.历史档案
		if ("t_archives".equalsIgnoreCase(table_name)) {
			// t_master.tuid t_master_detail.master_tuid t_archives.master_tuid
			// t_placement.master_tuid
			// t_house.house_status(5到1)
			String archives = getSQL(getResource("archives.sql"), inputParams);
			Recordset rs_archives = db.get(archives);
			if (rs_archives.getRecordCount() >0) {
				rs_archives.top();
				while(rs_archives.next()){
					String archives_1_house = getSQL(getResource("archives_1_house.sql"), rs_archives);
					String archives_1_jiesuan = getSQL(getResource("archives_1_jiesuan.sql"), rs_archives);
					
					String archives_2_placement= getSQL(getResource("archives_2_placement.sql"), rs_archives);
					String archives_3_self= getSQL(getResource("archives_3_self.sql"), rs_archives);
					String archives_4_master_detail= getSQL(getResource("archives_4_master_detail.sql"), rs_archives);
					String archives_5_master= getSQL(getResource("archives_5_master.sql"), rs_archives);
					db.exec(archives_1_house);
					db.exec(archives_1_jiesuan);
					
					db.exec(archives_2_placement);
					db.exec(archives_3_self);
					db.exec(archives_4_master_detail);
					db.exec(archives_5_master);
				}

			}
		}
		// 2.回迁录入
		if ("t_master".equalsIgnoreCase(table_name)) {
			// t_master.tuid t_master_detail.master_tuid  
			// t_fee.master_tuid
			// T_PLACEMENT.master_tuid(5到1)
			String archives = getSQL(getResource("master.sql"), inputParams);
			Recordset rs_master = db.get(archives);
			if (rs_master.getRecordCount() >0) {
				rs_master.top();
				while(rs_master.next()){
					System.out.println("t_master delete");
					String master_0_jiuchi = getSQL(getResource("master_0_jiuchi.sql"), rs_master);
					String master_1_house = getSQL(getResource("master_1_house.sql"), rs_master);
					String master_1_jiesuan = getSQL(getResource("master_1_jiesuan.sql"), rs_master);
					String master_2_placement= getSQL(getResource("master_2_placement.sql"), rs_master);
					String master_4_master_detail= getSQL(getResource("master_4_master_detail.sql"), rs_master);

                    //2011-03-09 增加对费用表的删除 anthony begin
                    String master_4_fee= getSQL(getResource("master_3_fee.sql"), rs_master);
                    //2011-03-09 end
					String master_5_master= getSQL(getResource("master_5_master.sql"), rs_master);
//					System.out.println("house:"+db.get(master_1_house).getRecordCount());
//					System.out.println("jiesuan:"+db.get(master_1_jiesuan).getRecordCount());
//					System.out.println("placement:"+db.get(master_2_placement).getRecordCount());
//					System.out.println("master_detail:"+db.get(master_4_master_detail).getRecordCount());
//					System.out.println("master:"+db.get(master_5_master).getRecordCount());
					
					db.exec(master_0_jiuchi);

					db.exec(master_1_house);
					db.exec(master_1_jiesuan);

					db.exec(master_2_placement);
					db.exec(master_4_master_detail);

                    //2011-03-09 增加对费用表的删除 anthony begin
                    db.exec(master_4_fee);
                    //2011-03-09 end

					db.exec(master_5_master);
				}

			}
		}

		return 0; // OK

	}

}
